package com.leff.cards.request;

import java.util.ArrayList;

import com.leff.cards.Dictionary;
import com.leff.cards.StoreWrapper;
import com.leff.cards.entity.Group;

public class GetInvites extends Request {
	
	public GetInvites(Dictionary dict) {
		super(dict);
	}
	
	public RequestResult doGetInvites() {
		
		RequestResult result = this.verifyRequiredParameters(Parameter.FB_ID);
		if(!result.isSuccessful()) {
			return result;
		}
		
		String idStr = (String)mDictionary.get(Parameter.FB_ID);
		long fbid = Long.parseLong(idStr);
		ArrayList<Group> invites = StoreWrapper.getInvitesForFbId(fbid);
		
		ArrayList<Object> json = new ArrayList<Object>();
		for(Group G : invites) {
			json.add(G.toJSON());
		}
		
		result.res = Dictionary.withObject("invites", json);
		
		return result;
	}
}
